﻿using MB.Orm.DB;
using MB.RuleBase.Common;
using Model;
using Public.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Service
{
    public class BLocationInfo
    {
        public BLocationInfo() { }


        /// <summary>
        /// 查询货位信息
        /// </summary>
        /// <param name="seedType"></param>
        /// <returns></returns>
        public List<Location> GetLocationInfoList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<Location> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<Location>("Location", "GetLocationInfo", pageIndex, pageSize, out  total, parValues);
                return list;
            }
        }

        /// <summary>
        /// 获取仓库
        /// </summary>
        /// <param name="seedType"></param>
        /// <returns></returns>
        public List<Warehouse> GetWarehouseList(string defaultValue)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<Warehouse> lmSeedlist = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<Warehouse>("Location", "GetWarehouseInfo");
                if (defaultValue != null && defaultValue != "")
                {
                    lmSeedlist.Add(new Warehouse() { WAREHOUSEID = 0, WAREHOUSECODE = "0", WAREHOUSENAME = defaultValue });

                }
                return lmSeedlist;
            }
        }

        /// <summary>
        /// 获取货位信息
        /// </summary>
        /// <param name="IsSetAll"></param>
        /// <returns></returns>
        public List<Location> GetLocationCodeList(string defaultValue, string where)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<Location> lstLocation = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml4<Location>("Location", "GetLocationCodeList", where);
                if (defaultValue != null && defaultValue != "")
                {
                    lstLocation.Add(new Location() { LOCATIONID = 0, LOCATIONCODE = defaultValue });
                }

                return lstLocation;
            }
        }

        /// <summary>
        /// 根据LocationCode获取货位
        /// </summary>
        /// <param name="locationCode"></param>
        /// <returns></returns>
        public Location CheckLocation(string locationCode)
        {
            Location Info = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<Location>("Location", "CheckLocation", locationCode).FirstOrDefault();
            return Info;
        }

        /// <summary>
        /// 新增货位信息
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public int AddLocation(Location location)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<Location>("Location", "AddLocation", location);
        }

        /// <summary>
        /// 修改货位信息
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public int UpdateLocationByID(Location location)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<Location>
                            ("Location", "UpdateLocationByID", location);
        }


        /// <summary>
        /// 查询临保商品信息
        /// </summary>
        /// <param name="seedType"></param>
        /// <returns></returns>
        public List<LocationInventoryBatch> GetLocationInventoryBatchList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<LocationInventoryBatch> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<LocationInventoryBatch>("Location", "GetLocationInventoryBatchList", pageIndex, pageSize, out  total, parValues);
                return list;
            }
        }

        /// <summary>
        /// 修改货位临保状态及延保时间
        /// </summary>
        /// <param name="locationInventoryId"></param>
        /// <returns></returns>
        public int UpdateLocationInventoryQualityStatus(int locationInventoryId, int saleDays)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQuery("Location", "UpdateLocationInventoryQualityStatus", locationInventoryId, saleDays);
        }



    }
}
